import numpy as np
import matplotlib.pyplot as plt
from pylab import *
import seaborn as sns

def Drawhistogram(x,y):
    font = {'family':  'SimSun',
            'size': 16,
            }
    sns.set(font_scale=1.2)
    plt.rc('font',family='SimSun')

    x = x
    y = y

    plt.figure(figsize=(14,8))
    plt.barh(range(len(y)), -x,color='#14B6DF',label='男生')
    plt.barh(range(len(x)), y,color='#ef929b',label='女生')

    plt.xlim((-1,1))
    plt.xticks((-1.2,-1,-0.5,0,0.5,1,1.2),
               ('120%','100%','50%','0%','50%','100%','120%'),
               font={'size':  18})
    plt.yticks((0, 1, 2, 3, 4, 5, 6,),
               (
                   '钙（mg.d-1）', '铁（mg.d-1）', '锌（mg.d-1）', '维生素A（μg.d-1）', '维生素B1（mg.d-1）', '维生素B2（mg.d-1）',
                   '维生素C（mg.d-1）',),
               font={'size':  12})
    plt.xlabel('摄入量与标准量比',fontdict={'size': 18})
    plt.title("男生与女生一天微量元素摄入进度",
              font={'size':  18})
    plt.legend(fontsize=16)
    plt.axvline(x=-0.9, color='#248669', linestyle='--')
    plt.axvline(x=-1.1, color='#248669', linestyle='--')
    plt.axvline(x=1.1, color='#248669', linestyle='--')
    plt.axvline(x=0.9, color='#248669', linestyle='--')
    # 修改填充条件
    plt.axvspan(-1.1, -0.9, color='#F1A340', alpha=0.3)
    plt.axvspan(0.9, 1.1, color='#F1A340', alpha=0.3)
    # 填充大于预测值的颜色区域
    plt.show()

if __name__=="__main__":
    Drawhistogram(np.array([0.737925,2.87875,1.058256,1.5602,1.184571429,0.877785714,1.4554]),#男
np.array([0.96060625,1.2238,1.430673333,1.147142857,1.145833333,0.6225,1.3655]))# 女


# 第一题
#
# 0.259125,0.566,0.836733333,0.428214286,0.75375,0.48,0.57,女

# 2.3
# 0.94138125,2.12975,1.005892,0.8993125,1.173928571,0.657857143,1.098, #男
# 0.485625,0.9947,1.200066667,0.560014286,0.997833333,0.624916667,0.5714, # 女

# 钙铁锌男
# 0.737925,2.87875,1.058256,1.5602,1.184571429,0.877785714,1.4554
#女
# 0.96060625,1.2238,1.430673333,1.147142857,1.145833333,0.6225,1.3655

